﻿Imports MySql.Data
Imports MySql.Data.MySqlClient
Module Modulo
    Private con As New Conexion
    Public Sub ocultarPaneles(ByVal frm As Panel)
        ''variable donde almaceno el control
        For Each paneles As Control In frm.Controls
            If TypeOf paneles Is Panel Then
                paneles.Visible = False
            End If
            If TypeOf paneles Is NumericUpDown Then
                paneles.Visible = False
            End If

        Next
    End Sub

    Public Sub llenarJuegos(ByVal comboBox As ComboBox)
        Try
            Dim tabla As New DataTable
            Dim datos As New MySqlDataAdapter("SELECT jue_id, jue_fecha FROM juegoprincipal", con.conexion)
            con.conectar()
            datos.Fill(tabla)
            If tabla.Rows.Count > 0 Then
                With (comboBox)
                    .DataSource = tabla
                    .DisplayMember = "jue_fecha"
                    .ValueMember = "jue_id"
                End With
                con.cerrar()
            Else
                MsgBox("No se han encontrado juegos almacenados.")
                FrmEleccionJuego.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Public Function obtenerMetodoJuego(ByVal idJuego As String)
        Dim comandoSQL As New MySqlCommand
        Dim estado As String = ""
        Try
            con.conectar()
            Dim sql As String = "SELECT met_nombre FROM juegoprincipal,metodos WHERE juegoprincipal.met_id=metodos.met_id AND juegoprincipal.jue_id= " & idJuego
            comandoSQL.Connection = con.conexion
            comandoSQL.CommandText = sql
            estado = comandoSQL.ExecuteScalar.ToString
            con.cerrar()
        Catch ex As Exception
        End Try
        Return estado

    End Function
    Public Sub calcular_costo()

        Dim costo As Integer = 0
        For i As Integer = 1 To grupbox1.empresas
            For j As Integer = 1 To grupbox1.bodegas
                If grupbox1.matriz(i, j).asignacion > 0 Then
                    costo = costo + (grupbox1.matriz(i, j).asignacion * grupbox1.matriz(i, j).costo)
                End If
            Next
        Next
        grupbox1.costo = costo
        grupbox1.Label52.Text = "Costo: " & FormatNumber(costo, 0)
    End Sub

    Public Sub PanelAMatriz()
        For i = 1 To grupbox1.empresas
            For j As Integer = 1 To grupbox1.bodegas
                For Each Control As Control In grupbox1.splitContainer1.Panel1.Controls
                    If Control.Name = "Panel" & i & j Then
                        grupbox1.matriz(i, j).verificacion = Val(Control.Controls.Item(0).Text)
                        grupbox1.matriz(i, j).costo = Val(Control.Controls.Item(2).Text)
                        If Control.Controls.Item(1).Text = "" Then
                            grupbox1.matriz(i, j).asignacion = 0
                        ElseIf Control.Controls.Item(1).Text = 0 Then
                            grupbox1.matriz(i, j).asignacion = -1
                        Else
                            grupbox1.matriz(i, j).asignacion = Control.Controls.Item(1).Text
                        End If
                    End If
                Next
            Next
        Next
    End Sub
End Module
